/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import models.Baskets;
import models.ItemBasket;
import models.Orders;
import models.ProductType;
import models.Products;
import services.interfaces.IProductService;

/**
 *
 * @author serga
 */
public class ProductsServiceImpl extends GenericServiceImpl<Products> implements IProductService {
    
    @PersistenceContext(unitName="ors-ejbPU2")
    private EntityManager em;

    
    public ProductsServiceImpl() {
        super(Products.class);
    }
   
    /*private List<Products> listProducts = new ArrayList<Products> ();*/
   
    @Override
    public List<Products> getProductsByType (ProductType type) {
        return (List<Products>)em.createNamedQuery("Products.getProductsByType").setParameter("id_type", type.getId()).getFirstResult() ;
    }

    @Override
    public List<Products> getOrderProducts (Orders order) {
        return (List<Products>)em.createNamedQuery("Products.getOrderProducts").setParameter("id_order", order.getId()).getFirstResult() ;
    }
    
    /*@Override
    public List<Products> getProductsByType(ProductType type) {
        List<Products> typeProduct = new ArrayList<Products>();
        for (Products item: this.listProducts) {
            if (item.getproductType() == type)
                typeProduct.add(item);
    }
        return typeProduct;
    }

    @Override
    public List<Products> getOrderProducts(Orders order) {
        List<Products> orderProduct = new ArrayList<Products>();
        for (Baskets item: order.getListBaskets()) {
            for (ItemBasket item1: item.getElementsList()) {
                orderProduct.add(item1.getProduct());
            }
    }
        return orderProduct;
    }
*/
    @Override
    public List<Products> getProductsByType(ProductType type) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Products> getOrderProducts(Orders order) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected EntityManager getEntityManager() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int count() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
